package service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mybatis.mapper.TeacherCKMapper;
import com.mybatis.po.TeacherCKinfo;



@Service
public class TeacherCheckService {
	@Autowired
	private TeacherCKMapper TeacherCKMapper;
	public List<Map<String,Object>> getcheckinfo1(String cid) {
		double sum=0;
		List<Map<String,Object>> ans=TeacherCKMapper.selectUinfoByCid(cid);//找出学生id姓名
		for(int i=0;i<ans.size();i++) {
			String uid=(String)ans.get(i).get("uid");
			List<Integer> teacherck=TeacherCKMapper.selectCKByUidCid(uid,cid);//找出学生ck
			for(int tmp:teacherck) {
				sum+=tmp;
			}
			double tmp1=Math.round(sum/teacherck.size()*10000)/100.0;
			sum=0;
			ans.get(i).put("percent",tmp1);
			System.out.println(ans.size());
			System.out.println(tmp1);
		}
		return ans;
	}

	public double getcheckinfo(String cid) {
		double ans;
		double sum=0;
		List<Integer> teacherck=TeacherCKMapper.selectCKByCid(cid);
		for(int tmp:teacherck) {
			sum+=tmp;
		}
		System.out.println(sum);
		ans=sum/teacherck.size();
		System.out.println(ans);
		ans=Math.round(ans*10000)/100.0;
		return ans;
	}
	public List<List<Object>> getinfo(String Cid){
		List<List<Object>> ans =new ArrayList<>();
		List<TeacherCKinfo> info=TeacherCKMapper.select3ByCid(Cid);
		for(TeacherCKinfo tmp:info) {
			List<Object> tmp1=new ArrayList<>();
			tmp1.add(tmp.getUid());
			System.out.println(tmp.getUid());
			tmp1.add(tmp.getUname());
			tmp1.add(tmp.getCheck1());
			tmp1.add(tmp.getCreated_at());
			ans.add(tmp1);
		}
		return ans;
	}
	public List<Map<String,Object>> getinfo1(String cid){
		List<Map<String,Object>> ans=TeacherCKMapper.selectUinfoByCid(cid);
		for(int i=0;i<ans.size();i++) {
			String uid=(String)ans.get(i).get("uid");
			List<Integer> teacherck=TeacherCKMapper.selectCKByUidCid3limit(uid,cid);//找出学生ck
			List<String> teacherct=TeacherCKMapper.selectCTByUidCid3limit(uid, cid);
			ans.get(i).put("check", teacherck);
			ans.get(i).put("created_at", teacherct);
		}
		return ans;
	}
}
